package com.topcoder.srm521;

import java.util.HashSet;

public class SquaredSubsets {
	public long countSubsets(int n, int[] x, int[] y) {
		HashSet<Integer> px = new HashSet<Integer>();
		HashSet<Integer> py = new HashSet<Integer>();
		n *= 2;
		for (int i=0; i<x.length; i++) {
			x[i] *= 2;
			y[i] *= 2;
			
			px.add(x[i]);
			px.add(x[i]-n-1);
			py.add(y[i]);
			py.add(y[i]-n-1);
		}
		
		HashSet<Long> res = new HashSet<Long>();
		for (int left : px) {
			for (int top : py) {
				long mask = 0;
				for (int k=0; k<x.length; k++) {
					if (inside(left, top, x[k], y[k], n)) {
						mask |= 1L << k;
					}
				}
				if (mask > 0) res.add(mask);
			}
		}
		
		return res.size();
	}
	
	private boolean inside(int left, int top, int x, int y, int n) {
		return x>=left && y>=top && x<=left+n && y<=top+n;
	}
}
